package com.yong.ssj.service.customer;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yong.ssj.db.dao.customer.IOrdinaryDao;
import com.yong.ssj.db.dao.sys.IUserDao;
import com.yong.ssj.db.dto.customer.CustomerDto;
import com.yong.ssj.db.dto.customer.MaterialDto;
import com.yong.ssj.vo.customer.MaterialVo;
import com.yong.ssj.vo.customer.RenzhenVo;
import com.yong.ssj.vo.customer.UpdategerenVo;
import com.yong.ssj.vo.customer.UpdatejiaVo;
import com.yong.ssj.vo.customer.jiashiVo;
import com.yong.ssj.vo.customer.twiceDrVo;
import com.yong.ssj.vo.customer.twiceIdVo;

@Service(value="OrdinaryServiceImpl")
public class OrdinaryServiceImpl implements IOrdinaryService{
	
	@Resource(name="userDaoImpl")
	private IUserDao userDao;
	
	@Resource(name="OrdinaryDaoImpl")
	private IOrdinaryDao ordinaryDao;

	@Override
	public List<Map<String, Object>> queryOrdinary() {
		// TODO Auto-generated method stub
		List<Map<String, Object>> list = ordinaryDao.queryOrdinary();
		return list;
	}

	@Override
	public CustomerDto queryCustomer(String phone) {
		// TODO Auto-generated method stub
		CustomerDto dto = ordinaryDao.queryPhone(phone);
		return dto;
	}

	@Override
	public MaterialVo queryDetails(String customer_id) {
		// TODO Auto-generated method stub
		MaterialDto dto = ordinaryDao.queryCustomer(Long.parseLong(customer_id));
		String phone = ordinaryDao.queryPhone(Long.parseLong(customer_id));
		MaterialVo vo = new MaterialVo();
		vo.setBank_card_1(dto.getBank_card_1());
		vo.setBank_card_1_status(dto.getBank_card_1_status());
		vo.setBank_card_2(dto.getBank_card_2());
		vo.setBank_card_2_status(dto.getBank_card_2_status());
		vo.setContact_file(dto.getContact_file());
		vo.setContact_file_status(dto.getContact_file_status());
		vo.setCustomer_id(dto.getCustomer_id());
		vo.setCustomer_name(phone);
		vo.setDriving_license_1(dto.getDriving_license_1());
		vo.setDriving_license_1_status(dto.getDriving_license_1_status());
		vo.setDriving_license_2(dto.getDriving_license_2());
		vo.setDriving_license_2_status(dto.getDriving_license_2_status());
		vo.setIdcard_1(dto.getIdcard_1());
		vo.setIdcard_1_status(dto.getIdcard_1_status());
		vo.setIdcard_2(dto.getIdcard_2());
		vo.setIdcard_2_status(dto.getIdcard_2_status());
		vo.setMaterial_id(dto.getMaterial_id());
		vo.setPhone_service_code(dto.getPhone_service_code());
		vo.setRz_money_limit(dto.getRz_money_limit());
		vo.setRz_status(dto.getRz_status());
		vo.setRz_surplus_money(dto.getRz_surplus_money());
		vo.setRz_type(dto.getRz_type());
		return vo;
	}

	@Override
	public List<Map<String, Object>> queryWait() {
		// TODO Auto-generated method stub
		List<Map<String, Object>> list = ordinaryDao.queryWait();
		return list;
	}

	@Override
	public List<Map<String, Object>> queryAuthe() {
		// TODO Auto-generated method stub
		List<Map<String, Object>> list = ordinaryDao.queryAuthenticated();
		return list;
	}

	@Override
	public int updateMaterial(MaterialVo vo) {
		// TODO Auto-generated method stub
		int yan = ordinaryDao.updateMaterial(vo);
		return yan;
	}

	@Override
	public int updateGeren(UpdategerenVo vo) {
		// TODO Auto-generated method stub
		int yan = 0;
		ordinaryDao.updateGR(vo);
		if(vo.getIdcard_1_status().equals("1")&&vo.getIdcard_2_status().equals("1")&&vo.getBank_card_1_status().equals("1")
				&&vo.getBank_card_2_status().equals("1")&&vo.getContact_file()!=null){
			ordinaryDao.updateStatus("2", vo.getMaterial_id());
			yan = ordinaryDao.updateCusStatus("1", vo.getCustomer_id());
		}else {
			yan = ordinaryDao.updateStatus("3", vo.getMaterial_id());
		}
		return yan;
	}

	@Override
	public int updateJS(UpdatejiaVo vo) {
		// TODO Auto-generated method stub
		int yan = 0;
		ordinaryDao.updateJS(vo);
		if(vo.getDriving_license_1_status().equals("1")&&vo.getDriving_license_2_status().equals("1")&&vo.getBank_card_1_status().equals("1")
				&&vo.getBank_card_2_status().equals("1")&&vo.getContact_file()!=null){
			 ordinaryDao.updateStatus("2", vo.getMaterial_id());
			yan = ordinaryDao.updateCusStatus("1", vo.getCustomer_id());
		}else {
			yan = ordinaryDao.updateStatus("3", vo.getMaterial_id());
		}
		return yan;
	}

	@Override
	public List<Map<String, Object>> indexst(String customer_id) {
		// TODO Auto-generated method stub
		return ordinaryDao.materialStatus(Long.parseLong(customer_id));
	}

	@Override
	public int renzhenPt(RenzhenVo vo, String customer_id) {
		// TODO Auto-generated method stub
		userDao.zeng(Long.parseLong(customer_id));
		ordinaryDao.updateGRuse(vo, Long.parseLong(customer_id));
		int yan=ordinaryDao.updateGRma(vo,Long.parseLong(customer_id));
		return yan;
	}

	@Override
	public int jiashiPt(jiashiVo vo, String customer_id) {
		// TODO Auto-generated method stub
		userDao.zeng(Long.parseLong(customer_id));
		ordinaryDao.updateJSuse(vo, Long.parseLong(customer_id));
		int yan = ordinaryDao.updateJSma(vo, Long.parseLong(customer_id));
		return yan;
	}

	@Override
	public int updateziliao(String zfb_code, String wx_code, String address, long customer_id) {
		// TODO Auto-generated method stub
		return ordinaryDao.updateziliao(zfb_code, wx_code, address, customer_id);
	}

	@Override
	public MaterialDto chaxun(long customer_id) {
		// TODO Auto-generated method stub
		MaterialDto dto = ordinaryDao.queryCustomer(customer_id);
		return dto;
	}

	@Override
	public CustomerDto queryCus(long customer_id) {
		// TODO Auto-generated method stub
		CustomerDto dto = ordinaryDao.queryCuser(customer_id);
		return dto;
	}

	@Override
	public int updatePassword(String customer_password, long customer_id) {
		// TODO Auto-generated method stub
		return ordinaryDao.updatePassword(customer_password, customer_id);
	}

	@Override
	public int updateTwiceID(twiceIdVo vo, long customer_id) {
		// TODO Auto-generated method stub
		return ordinaryDao.updateTwiceID(vo, customer_id);
	}

	@Override
	public int updateTwiceDr(twiceDrVo vo, long customer_id) {
		// TODO Auto-generated method stub
		return ordinaryDao.updateTwiceDr(vo, customer_id);
	}


}
